import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [{
  path: '/main',
  name: 'Main',
  redirect: "/home",
  component: () => import("../views/Main.vue"),
  children: [{
      path: '/home',
      component: () => import("../views/Announcement.vue"),
    }, {
      path: '/student/schedule',
      component: () => import("../views/student/ScheduleShow.vue"),
      meta: {
        requiresAuth: 0
      }
      //教师和学生共用1
    }, {
      path: '/student/grade',
      component: () => import("../views/student/GradeShow.vue"),
      meta: {
        requiresAuth: 0
      }
    }, {
      path: '/student/info',
      component: () => import("../views/student/InfoShow.vue"),
      meta: {
        requiresAuth: 0
      }
      //教师和学生共用
    }, {
      path: '/student/editPassword',
      component: () => import("../views/student/EditePassword.vue"),
      meta: {
        requiresAuth: 0
      }
    }, {
      path: '/manager/teacherList',
      component: () => import("../views/manager/TeacherList.vue"),
      meta: {
        requiresAuth: 2
      }
    }, {
      path: '/manager/teacherEdit/:id',
      component: () => import("../views/manager/TeacherEdit.vue"),
      meta: {
        requiresAuth: 2
      }
    }, {
      path: '/manager/grade/list',
      component: () => import("../views/manager/GradeList.vue"),
      meta: {
        requiresAuth: 2
      }
    },
    {
      path: '/manager/studentList',
      component: () => import("../views/manager/StudentList.vue"),
      meta: {
        requiresAuth: 2
      }
    }, {
      path: '/manager/studentEdit/:id',
      component: () => import("../views/manager/StudentEdit.vue"),
      meta: {
        requiresAuth: 2
      }
    }, {
      path: '/manager/scheduleEdit/:id',
      component: () => import("../views/manager/ScheduleEdit.vue"),
      meta: {
        requiresAuth: 2
      }
      //用以添加和删除课程的，课表的是下一个
    }, {
      path: '/manager/scheduleList',
      component: () => import("../views/manager/ScheduleList.vue"),
      meta: {
        requiresAuth: 2
      }
    }, {
      path: '/manager/curriculumEdit',
      component: () => import("../views/manager/CurriculumEdit.vue"),
      meta: {
        requiresAuth: 2
      }
      //课表功能页面
    }, {
      path: '/manager/collegeEdit',
      component: () => import("../views/manager/CollegeEdit.vue"),
      meta: {
        requiresAuth: 2
      }
    }, {
      path: '/manager/departmentEdit',
      component: () => import("../views/manager/Department.vue"),
      meta: {
        requiresAuth: 2
      }
    }, {
      path: '/manager/userEdit',
      component: () => import("../views/manager/UserEdit.vue"),
      meta: {
        requiresAuth: 2
      }
    }, {
      path: '/manager/speciallyList',
      component: () => import('../views/manager/Specially.vue'),
      meta: {
        requiresAuth: 2
      }
    }, {
      path: '/manager/classEdit',
      component: () => import('../views/manager/ClassEdit.vue'),
      meta: {
        requiresAuth: 2
      }
    },
    {
      path: '/manager/managerList',
      component: () => import('../views/manager/AdminList.vue'),
      meta: {
        requiresAuth: 2
      }
    },
    {
      path: '/teacher/info',
      component: () => import("../views/teacher/ShowInfo.vue"),
      meta: {
        requiresAuth: 1
      }
    },
    {
      path: '/teacher/schedule',
      component: () => import("../views/teacher/ScheduleShow.vue"),
      meta: {
        requiresAuth: 1
      }
    },
    {
      path: '/teacher/editPassword',
      component: () => import("../views/teacher/EditPassword.vue"),
      meta: {
        requiresAuth: 1
      }
    },
    {
      path: '/teacher/gradeEdit',
      component: () => import("../views/teacher/GradeEdit.vue"),
      meta: {
        requiresAuth: 1
      }
    }
  ]
}, {
  path: "/",
  name: 'Login',
  component: () => import("../views/Login.vue")
}]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  let identity = sessionStorage.identity;
  if (!to.meta.requiresAuth) {
    next()
  } else if (to.meta.requiresAuth && to.meta.requiresAuth == identity) {
    next()
  } else {
    next('/')
  }
})
export default router